/**
 * 模块：医院入驻平台-SysOrg
 */
package design.onekey.controller;

import design.onekey.annotation.Check;
import design.onekey.annotation.LoginUser;
import design.onekey.annotation.MethodLog;
import design.onekey.annotation.NoRepeatSubmit;
import design.onekey.base.BaseEntity;
import design.onekey.base.Response;
import design.onekey.constant.Constants;
import design.onekey.model.dto.UserInfoDto;
import design.onekey.model.SysOrg;
import design.onekey.service.ISysOrgService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @Description: SysOrgcontroller类
* @author
* @date 2020-06-05 04:03:14
* @version V1.0
*/
@RestController
@RequestMapping("/api/sysOrg")
public class SysOrgController extends BaseController {

   /**
    * iSysOrgService服务注入
    */
   @Autowired
   private ISysOrgService iSysOrgService;


    /**
     * @Description: 分页查询表格
     * @param model
     * @param @return
     * @return BaseEntity
     * @throws
     */
    @ApiOperation(value="SysOrg-获取表格数据", notes="获取表格数据")
    @RequestMapping(value = "/getTableList",method = RequestMethod.POST)
    @MethodLog(module="SysOrg",remark="获取页面表格数据",operateType=Constants.OPERATE_TYPE_SEARCH)
    public Response getTableList(@RequestBody SysOrg model, @LoginUser UserInfoDto userInfoDto)
    {
        BaseEntity result = new BaseEntity();
        result = iSysOrgService.tablePagingQueryByAuthority(model,userInfoDto);
        return Response.success(result);
    }

    /**
     * @Description: 获取详细信息
     * @param id
     * @param @return  BaseEntity
     * @return
     * @throws
     */
    @ApiOperation(value="SysOrg-获取详细信息", notes="根据id获取详细信息")
    @RequestMapping(value = "/getDetail",method = RequestMethod.GET)
    @MethodLog(module="SysOrg",remark="获取详细信息",operateType=Constants.OPERATE_TYPE_SEARCH)
    @Check({"id:required#主键ID"})
    public Response getDetail(@RequestParam Long id) throws Exception
    {
        BaseEntity result = iSysOrgService.getDetail(id);
        return Response.success(result);
    }

    /**
     * @throws Exception
     * @Description: 新增
     * @param model
     * @return BaseEntity
     * @throws
     */
    @ApiOperation(value="SysOrg-新增数据", notes="新增数据")
    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    @MethodLog(module="SysOrg",remark="新增",operateType=Constants.OPERATE_TYPE_ADD)
    @Check({"orgCode:required#组织编码;length#组织编码#20","orgName:required#组织名称;length#组织名称#30","orgType:required#组织类型;"})
    @NoRepeatSubmit
    public Response insert(@RequestBody SysOrg model,@LoginUser UserInfoDto userInfoDto) throws Exception
    {
        BaseEntity result = iSysOrgService.insert(model,userInfoDto);
        return Response.success(result.getStatusMsg());
    }

    /**
     * @throws Exception
     * @Description: 更新
     * @param model
     * @return  BaseEntity
     * @throws
     */
    @ApiOperation(value="SysOrg-更新数据", notes="更新数据")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @MethodLog(module="SysOrg",remark="更新",operateType=Constants.OPERATE_TYPE_UPDATE)
    @Check({"id:required#主键ID","orgCode:required#组织编码;length#组织编码#20","orgName:required#组织名称;length#组织名称#30","orgType:required#组织类型;"})
    @NoRepeatSubmit
    public Response update(@RequestBody SysOrg model,@LoginUser UserInfoDto userInfoDto) throws Exception
    {
        BaseEntity result = iSysOrgService.update(model,userInfoDto);
        return Response.success(result.getStatusMsg());
    }

    /**
     * @Description: 单条删除
     * @param id
     * @return  BaseEntity
     * @throws
     */
    @ApiOperation(value="SysOrg-单条删除数据", notes="根据主键删除数据")
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    @MethodLog(module="SysOrg",remark="单条删除",operateType= Constants.OPERATE_TYPE_DELETE)
    @Check({"id:required#主键ID"})
    @NoRepeatSubmit
    public Response delete(@RequestParam Long id)
    {
        BaseEntity result = iSysOrgService.delete(id);
        return Response.success(result.getStatusMsg());
    }

    /**
     * @Description: 批量删除
     * @param ids
     * @return BaseEntity
     * @throws
     */
    @ApiOperation(value="SysOrg-批量删除", notes="批量删除数据")
    @RequestMapping(value = "/deletebatch",method = RequestMethod.POST)
    @MethodLog(module="SysOrg",remark="批量删除",operateType=Constants.OPERATE_TYPE_BATCHDELETE)
    @NoRepeatSubmit
    public Response deletebatch(@RequestBody List<Long> ids)
    {
        BaseEntity result = iSysOrgService.deleteBatch(ids);
        return Response.success(result.getStatusMsg());
    }

    /**
     * @Method getNextLayer
     * @Author zhangcheng
     * @Version  1.0
     * @Description 根据父节点查询下一层子结构
     * @Return java.util.List<com.baiyyy.yfz.entity.sysorg.SysOrg>
     * @Exception
     * @Date 2020-6-8 11:41
     */
    @ApiOperation(value="SysOrg-获取下一层子结构", notes="根据父节点查询下一层子结构")
    @RequestMapping(value = "/getNextLayer",method = RequestMethod.GET)
    @MethodLog(module="SysOrg",remark="根据父节点查询下一层子结构",operateType=Constants.OPERATE_TYPE_SEARCH)
    @Check({"id:required#主键ID"})
    public Response getNextLayer(Long id,@LoginUser UserInfoDto userInfoDto){
        List<SysOrg> result = iSysOrgService.getNextLayer(id,userInfoDto);
        return Response.success(result);
    }


    /**
     * @Method getOrgTreeById
     * @Author zhangcheng
     * @Version  1.0
     * @Description 根据父节点查询组织机构树
     * @Return com.baiyyy.yfz.base.BaseEntity
     * @Exception
     * @Date 2020-6-8 15:21
     */
    @ApiOperation(value="SysOrg-获取组织机构树", notes="根据父节点查询组织机构树")
    @RequestMapping(value = "/getOrgTreeById",method = RequestMethod.GET)
    @MethodLog(module="SysOrg",remark="根据父节点查询下一层子结构",operateType=Constants.OPERATE_TYPE_SEARCH)
    @Check({"id:required#主键ID"})
    public Response getOrgTreeById(Long id){
        BaseEntity result = iSysOrgService.getOrgTreeById(id);
        return Response.success(result);
    }

}
